//
//  LGSettingViewController.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2023/2/15.
//

#import "LGSettingViewController.h"
//更换手机
#import "LGChangePhoneController.h"
//修改密码
#import "LGCheckPhoneController.h"
//注销账号
#import "LGCloseAccountController.h"
//关于
#import "LGAboutViewController.h"

#import "LGNavigationController.h"
#import "LGLoginViewController.h"
#import "LGLineTitleTipView.h"

#define lineHeight  viewPix(52)
@interface LGSettingViewController ()

/**   */
@property (nonatomic , strong)UIView *topView;
/**   */
@property (nonatomic , strong)LGLineTitleTipView *phoneView;
/**   */
@property (nonatomic , strong)LGLineTitleTipView *passwordView;
/**   */
@property (nonatomic , strong)LGLineTitleTipView *accountView;
/**   */
@property (nonatomic , strong)LGLineTitleTipView *notificationView;
/**   */
@property (nonatomic , strong)LGLineTitleTipView *aboutView;
/**   */
@property (nonatomic , strong)UIButton *logoutBtn;

@end

@implementation LGSettingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"设置";
    [self.view addSubview:self.topView];
    [self.topView addSubview:self.phoneView];
    [self.topView addSubview:self.passwordView];
    [self.topView addSubview:self.accountView];
    [self.view addSubview:self.aboutView];
    [self.view addSubview:self.logoutBtn];
    [self.view addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(bottomViewTapAction:)]];
}

-(void)topViewTapAction:(UITapGestureRecognizer *)sender{
    CGPoint point = [sender locationInView:self.topView];
    if(CGRectContainsPoint(self.phoneView.frame, point)){
        //换绑手机
        LGChangePhoneController *controller = [[LGChangePhoneController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if(CGRectContainsPoint(self.passwordView.frame, point)){
        //修改密码
        LGCheckPhoneController *controller = [[LGCheckPhoneController alloc]init];
        controller.phone = kPhone;
        controller.backVC = self;
        [self.navigationController pushViewController:controller animated:YES];
        
    }else if(CGRectContainsPoint(self.accountView.frame, point)){
        //注销账户
        LGCloseAccountController *controller = [[LGCloseAccountController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
    }
}

-(void)bottomViewTapAction:(UITapGestureRecognizer *)sender{
    CGPoint point = [sender locationInView:self.view];
    if(CGRectContainsPoint(self.aboutView.frame, point)){
        //关于
        LGAboutViewController *controller = [[LGAboutViewController alloc]init];
        [self.navigationController pushViewController:controller animated:YES];
       
    }
}

//退出登录
-(void)logoutBtnAction{
    [LGLoginManager logoutAction];
}


-(UIView *)topView{
    if(!_topView){
        _topView = [UIView shadowViewWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _topView.frame = CGRectMake(viewPix(16), viewPix(16), Screen_W-viewPix(32), viewPix(156));
        _topView.backgroundColor = [UIColor whiteColor];
        [_topView addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(topViewTapAction:)]];
    }
    return _topView;
}

-(LGLineTitleTipView *)phoneView{
    if(!_phoneView){
        _phoneView = [[LGLineTitleTipView alloc] initWithFrame:CGRectMake(0, 0, Screen_W-viewPix(32), lineHeight)];
        _phoneView.title = @"换绑手机";
        _phoneView.type = @"text";
        _phoneView.content = [kPhone stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"];
    }
    return _phoneView;
}

-(LGLineTitleTipView *)passwordView{
    if(!_passwordView){
        _passwordView = [[LGLineTitleTipView alloc] initWithFrame:CGRectMake(0, kMaxY(self.phoneView.frame), Screen_W-viewPix(32), lineHeight)];
        _passwordView.title = @"修改密码";
        _passwordView.type = @"text";
    }
    return _passwordView;
}

-(LGLineTitleTipView *)accountView{
    if(!_accountView){
        _accountView = [[LGLineTitleTipView alloc] initWithFrame:CGRectMake(0, kMaxY(self.passwordView.frame), Screen_W-viewPix(32), lineHeight)];
        _accountView.lineView.hidden = YES;
        _accountView.title = @"注销账户";
        _accountView.type = @"text";
    }
    return _accountView;
}

-(LGLineTitleTipView *)notificationView{
    if(!_notificationView){
        _notificationView = [[LGLineTitleTipView alloc] initWithFrame:CGRectMake(viewPix(16), kMaxY(self.topView.frame)+viewPix(16), Screen_W-viewPix(32), lineHeight)];
        [_notificationView setShadoWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _notificationView.lineView.hidden = YES;
        _notificationView.backgroundColor = [UIColor whiteColor];
        _notificationView.title = @"免打扰模式";
        _notificationView.type = @"text";
    }
    return _notificationView;
}

-(LGLineTitleTipView *)aboutView{
    if(!_aboutView){
        _aboutView = [[LGLineTitleTipView alloc] initWithFrame:CGRectMake(viewPix(16), kMaxY(self.topView.frame)+viewPix(16), Screen_W-viewPix(32), lineHeight)];
        [_aboutView setShadoWithColor:@"#B3C5D9" offset:CGSizeMake(0, 2) opacity:0.15 radius:15];
        _aboutView.lineView.hidden = YES;
        _aboutView.backgroundColor = [UIColor whiteColor];
        _aboutView.title = @"关于我们";
        _aboutView.type = @"text";
    }
    return _aboutView;
}

-(UIButton *)logoutBtn{
    if(!_logoutBtn){
        _logoutBtn = [UIButton buttonWithTitle:@"退出登录" topMargin:kMaxY(self.aboutView.frame)+viewPix(176)];
        [_logoutBtn addTarget:self action:@selector(logoutBtnAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _logoutBtn;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
